package com.lujianfei.powersearch.ui.report

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.gyf.immersionbar.ImmersionBar
import com.lujianfei.powersearch.R
import com.lujianfei.powersearch.base.BaseActivity
import com.lujianfei.powersearch.database.SearchItemModel
import com.lujianfei.powersearch.databinding.ActivityTotalConsumeReportBinding
import com.lujianfei.powersearch.ui.report.viewmodel.TotalConsumeReportViewModel
import com.lujianfei.powersearch.utils.ResUtils
import com.lujianfei.powersearch.utils.SnapshotUtils
import com.lujianfei.powersearch.utils.StatusBarUtils
import com.lujianfei.powersearch.utils.ToastUtils

/**
 * 总消费报告
 */
class TotalConsumeReportActivity : BaseActivity<ActivityTotalConsumeReportBinding>() {

    companion object {
        fun start(context: Context, item: SearchItemModel) {
            context.startActivity(
                Intent(
                    context,
                    TotalConsumeReportActivity::class.java
                ).putExtra("data", item)
            )
        }
    }

    private val mTotalConsumeReportViewModel: TotalConsumeReportViewModel by lazy { buildViewModel() }

    override fun resourceId() = R.layout.activity_total_consume_report

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true).statusBarColor(R.color.white).init()
        binding?.vm = mTotalConsumeReportViewModel
    }

    override fun initData() {
        parseIntent()
    }

    override fun initEvent() {
        binding?.btSave?.setOnClickListener {
            binding?.reportList?.let {
                SnapshotUtils.getRecyclerViewScreenshot(it)?.let { bitmap ->
                    SnapshotUtils.saveBitmap2Gallery(fileName = "consume_report", bitmap = bitmap)
                    ToastUtils.show("保存成功")
                }
            }
        }
    }

    private fun parseIntent() {
        mTotalConsumeReportViewModel.mSearchItemModel = intent?.getParcelableExtra("data")
        mTotalConsumeReportViewModel.generateReport()
    }
}